'use strict';
const db = uniCloud.database();
const dbCmd = db.command
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const {
		username,
		goods_id
	} = event
	const userInfo = await db.collection('uni-id-users').where({
		username: username
	}).get()
	const collect = userInfo.data[0].collect
	let dbCmdFuns = null
	if (collect.includes(goods_id)) {
		dbCmdFuns = dbCmd.pull(goods_id)
	} else {
		dbCmdFuns = dbCmd.addToSet(goods_id)
	}
	await db.collection('uni-id-users').where({
		username: username
	}).update({
		collect: dbCmdFuns
	})
	console.log('event : ', event)

	//返回数据给客户端
	return event
};
